﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="tablecloth/tablecloth.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="tablecloth/tablecloth.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>

<?php


$matchId = $_GET["matchID"];

if ($_GET["type"]!=1)
{
	include("inc/joomlaInt.php");
	include("inc/inc_configuration.php");
	include("inc/inc_kommentare.php");
}

if ($jUser==0)
{
	echo "Bitte zuerst einloggen!";
}
else
{

$matchId = $_GET["matchID"];


//Abfragen
$query = "	SELECT 	t1.id AS tHi,
					t2.id AS tGi,
					t1.name AS tHn, 
					t2.name AS tGn, 
					u1.username AS uHn, 
					u2.username AS uGn, 
					u1.id AS uHi, 
					u2.id AS uGi, 
					m.homeG AS hG, 
					m.guestG AS gG ,
					m.playdate AS pd,
					m.leagueId AS lid
			FROM 	$tbl_matches m, 
					$tbl_combinations c1, 
					$tbl_combinations c2, 
					$tbl_teams t1, 
					$tbl_teams t2, 
					$tbl_users u1, 
					$tbl_users u2
			WHERE
				m.id=$matchId
				AND
				
				m.homeC=c1.Id
				AND
				c1.userId=u1.Id
				AND
				c1.teamId=t1.id
				
				AND
				m.guestC=c2.id
				AND
				c2.userId=u2.Id
				AND
				c2.teamId=t2.id
				";
		
		$ergebnis = mysql_query($query);
		
		$row = mysql_fetch_object($ergebnis);
		
		$tHi = $row->tHi;
		$tGi = $row->tGi;
		$tHn = $row->tHn;
		$tGn = $row->tGn;
		$uHn = $row->uHn;
		$uGn = $row->uGn;
		$uHi = $row->uHi;
		$uGi = $row->uGi;
		$hG = $row->hG;
		$gG = $row->gG;
		$lid = $row->lid;
		
		$q="SELECT lp.path AS path FROM $tbl_leagues l, $tbl_leaguepics lp WHERE l.id=$lid AND l.picId=lp.id";
		$qe=mysql_query($q);
		$qeo=mysql_fetch_object($qe);
		$path=$qeo->path;

		$timestamp=$row->pd;
		$pd=date("d.m.y - H:i",$timestamp);
		
		
		
		
		echo 	"
				<table>
				<tr>
					<th colspan='3'></th>
				</tr>	
				<tr>	
					<td colspan='3'><center><img src='img/leagues/",$path,"' width='$leaguelogowidth' height='$leaguelogoheight' alt='$l1n'></center></td>
				</tr>
				<tr>
					<td width='40%'><center><a href='spiele_team.php?team=$tHi&liga=$lid'>$tHn</a><br><a href='team_kader.php?team=$tHi'><img src='img/logos/",$tHi,".png' width='50' height='50' alt=''></a><br><a href='profil.php?id=$uHi'>$uHn</a></center></td>
					<td width='20%'><center> vs. </center></td>
					<td width='40%'><center><a href='spiele_team.php?team=$tGi&liga=$lid'>$tGn</a><br><a href='team_kader.php?team=$tGi'><img src='img/logos/",$tGi,".png' width='50' height='50' alt=''></a><br><a href='profil.php?id=$uGi'>$uGn</a></center></td>
				</tr>
				<tr>
					<td colspan='3'><center>$pd</center></td>
					
				</tr>
				<tr>
					<td class='tor'><center>$hG</center></td>
					<td class='tor'><center> : </center></td>
					<td class='tor'><center>$gG</center></td>
				</tr>
				<tr>
					<th colspan='3'></th>
				</tr>
				</table><br>";
				
				
		$eQs =	"SELECT 
				e.minute 
				
				FROM 
				$tbl_events e, 
				$tbl_players p
				
				WHERE 
				e.matchId=$matchId AND 
				e.playerId=p.id
				
				Group BY 	
				e.minute
				";
		$eQe = mysql_query($eQs);
		$manz = mySQL_num_rows($eQe);
		
		if ($manz>0)
		{
			$shg=0;
			$sgg=0;
			
				echo "<table>
						<tr>
							<th colspan='5'></th>
						</tr>"; //<colgroup span=''></colgroup>
				while ($row = mysql_fetch_object($eQe))
					{
						$stand="";
						
						$m = $row->minute;
						echo "<tr><td>$m. Minute</td>";
						
						$eWm="	SELECT type,name,firstname,e.teamId FROM $tbl_events e, $tbl_players p WHERE 
								e.minute=$m AND 
								e.playerId=p.id AND
								e.matchId=$matchId
								ORDER BY type,teamId";
						$eWw=mysql_query($eWm);
						
						$count=0;
						while ($mrow = mysql_fetch_object($eWw))
						{
							$ds=0;
							
							$t = $mrow->type;
							$pnn = $mrow->name;
							$pfn = $mrow->firstname;
							$tId = $mrow->teamId;
							
							if (($t==1) OR ($t==5) OR ($t==6))
							{
								if ($tId==$tHi)
								{
									if ($t==6){$sgg++;} else {$shg++;}
									$stand="$shg:$sgg";
									$ds=1;
								}
								else
								{
									if ($tId==$tGi)
									{
										if ($t==6){$shg++;} else {$sgg++;}
										$stand="$shg:$sgg";
										$ds=1;
									}
								}
							}
							
							// if ($count>0)
							// {
								// echo "<br>";
							// }
							switch ($t)
							{
								case (1);
								$tn = "<img src='img/goal.png' alt='Tor' class='rechts' align='middle'>";
								break;
								
								case (2);
								$tn = "<img src='img/yellow.png' alt='Gelbe Karte' class='rechts' align='middle'>";
								break;
								
								case (3);
								$tn = "<img src='img/yellowred.png' alt='Gelb-Rote Karte' class='rechts' align='middle'>";
								break;
								
								case (4);
								$tn = "<img src='img/red.png' alt='Rote Karte' class='rechts' align='middle'>";
								break;
								
								case (5);
								$tn = "<img src='img/penalty.png' alt='Rote Karte' class='rechts' align='middle'>";
								break;
								
								case (6);
								$tn = "<img src='img/owngoal.png' alt='Eigentor' class='rechts' align='middle'>";
								break;
							}
							
							
							$tl = "<img src='img/logos/";
							$tl.=$tId;
							$tl.=".png' width='20' height='20' class='rechts' align='middle'>";
							
							$tstand="";
							
							if ($ds==1)
							{
								$tstand=$stand;
							}
							
							if ($count>0)
							{
								echo"</tr><tr><td> </td><td>$tstand </td><td>$tn</td><td>$pfn $pnn</td><td>$tl</td>";
							}
							else
							{
								echo"<td>$tstand </td><td>$tn</td><td>$pfn $pnn</td><td>$tl</td>";
							}
							$count++;
						}
						echo"</td></tr>";
						
					}
				
				
						
						
						
						
				echo "	<tr>
							<th colspan='5'></th>
						</tr>
						</table>";
	}
	
	
	if ($_GET["type"]!=1)
	{
	
		echo "<table>
				<tr>
					<th colspan='2'>Kommentare</th>
				</tr>
			";
			
		// Kommentare ausgeben
		
		$out=getKommentare($matchId);
		
		echo $out;
		
		echo '<tr>
				<td>Kommentar hinzufügen:</td>
				<td><form action="neuer_kommentar.php" method="post">
					<textarea name="comment" cols="50" rows="10" wrap="soft"></textarea>
					<input type="hidden" name="user" value="',$jUser,'">
					<input type="hidden" name="match" value="',$matchId,'"></td>
			  </tr>
			  <tr>
				<td colspan="2"><input type="submit" value="Kommentieren" class="button eintragen"></td><td></td>
			  </tr></form>';
	
		echo "<tr><th colspan='2'></th><tr></table>";
		
		echo "	<table>
					<tr>
						<td width='50%'><center><a href='javascript:window.history.back()' class='button zurueck'>Zurück</a></center></td>
					</tr>
				</table>";
	}
}		
						//javascript:window.history.back()
?>

</body>
</html>